IME_GET(WinTitle="")
{
    ifEqual WinTitle,,  SetEnv,WinTitle,A
    WinGet,hWnd,ID,%WinTitle%
    DefaultIMEWnd := DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)
 
    ;Message : WM_IME_CONTROL  wParam:IMC_GETOPENSTATUS
    DetectSave := A_DetectHiddenWindows
    DetectHiddenWindows,ON
    SendMessage 0x283, 0x005,0,,ahk_id %DefaultIMEWnd%
    DetectHiddenWindows,%DetectSave%
    Return ErrorLevel
}

IME_SET(setSts, WinTitle="")
{
    ifEqual WinTitle,,  SetEnv,WinTitle,A
    WinGet,hWnd,ID,%WinTitle%
    DefaultIMEWnd := DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)
 
    ;Message : WM_IME_CONTROL  wParam:IMC_SETOPENSTATUS
    DetectSave := A_DetectHiddenWindows
    DetectHiddenWindows,ON
    SendMessage 0x283, 0x006,setSts,,ahk_id %DefaultIMEWnd%
    DetectHiddenWindows,%DetectSave%
    Return ErrorLevel
}

isTypingPinYinWin() {
    ; 适用蓝底白字老版本，Win11白皮肤接口失效，因为窗口常驻后台，如是Win11请将本段删掉、将下一段开头的;去掉
    return WinExist("ahk_class Microsoft.IME.UIManager.CandidateWindow.Host")
}

;isTypingPinYinWin() {
;    ; 适用新版微软拼音，截图桃心
;    CoordMode "Pixel"  ; 将下面的坐标解释为相对于屏幕而不是活动窗口.
;    return ImageSearch(FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, "bin\img\IMElogo.png")
;}

global TypingSelection :=1

^!K::
Suspend
return

~Shift Up::
If(A_PriorKey="LShift" || A_PriorKey="RShift")
{
Send, {Ctrl}
}
return

~#.::
return

`::
If (IME_GET()=1) ;1 is CN
	Send, · ; CN
else
	Send, {u+0060} ; EN
return

+`::
If (IME_GET()=1) ;1 is CN
	Send, {u+007e} ; CN
else
	Send, {u+007e} ; EN
return

+1::
If (IME_GET()=1) ;1 is CN
	Send, ！ ; CN
else
	Send, {u+0021} ; EN
return

+2::
If (IME_GET()=1) ;1 is CN
	Send, {u+0040} ; CN
else
	Send, {u+0040} ; EN
return

+3::
If (IME_GET()=1) ;1 is CN
	Send, {u+0023} ; CN
else
	Send, {u+0023} ; EN
return

+4::
If (IME_GET()=1) ;1 is CN
{
	Send, ￥ ; CN
}
else
{
	Send, {u+0024} ; EN
}
return

+5::
If (IME_GET()=1) ;1 is CN
	Send, {u+0025} ; CN
else
	Send, {u+0025} ; EN
return

+6::
If (IME_GET()=1) ;1 is CN
	Send, …… ; CN
else
	Send, {u+005e} ; EN
return

+7::
If (IME_GET()=1) ;1 is CN
	Send, {u+0026} ; CN
else
	Send, {u+0026} ; EN
return

+8::
If (IME_GET()=1) ;1 is CN
	Send, {u+002a} ; CN
else
	Send, {u+002a} ; EN
return

+9::
If (IME_GET()=1) ;1 is CN
	Send, （ ; CN
else
	Send, {u+0028} ; EN
return

+0::
If (IME_GET()=1) ;1 is CN
	Send, ） ; CN
else
	Send, {u+0029} ; EN
return

+-::
If (IME_GET()=1) ;1 is CN
	Send, —— ; CN
else
	Send, {u+005F} ; EN
return

*-::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+002D} ; EN
}
else
	Send, -
return

+=::
Send, {u+002B} ; EN
return

*=::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+003D} ; EN
}
else
	Send, =
return

*1::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+0031}
	TypingSelection = 0
}
else
{
	Send, 1
	TypingSelection = 1
}
return

*2::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+0032}
	TypingSelection = 0
}
else
{
	Send, 2
	TypingSelection = 1
}
return

*3::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+0033}
	TypingSelection = 0
}
else
{
	Send, 3
	TypingSelection = 1
}
return

*4::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+0034}
	TypingSelection = 0
}
else
{
	Send, 4
	TypingSelection = 1
}
return

*5::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+0035}
	TypingSelection = 0
}
else
{
	Send, 5
	TypingSelection = 1
}
return

*6::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+0036}
	TypingSelection = 0
}
else
{
	Send, 6
	TypingSelection = 1
}
return

*7::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+0037}
	TypingSelection = 0
}
else
{
	Send, 7
	TypingSelection = 1
}
return

*8::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+0038}
	TypingSelection = 0
}
else
{
	Send, 8
	TypingSelection = 1
}
return

*9::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+0039}
	TypingSelection = 0
}
else
{
	Send, 9
	TypingSelection = 1
}
return

*0::
If (isTypingPinYinWin()=0) ;
{
	Send, {u+0030}
	TypingSelection = 0
}
else
{
	Send, 0
	TypingSelection = 1
}
return

+{::
Send, {u+007B}
return

*[::
If (isTypingPinYinWin()=0) ;
{
If (IME_GET()=1) ;1 is CN
	Send, 【 ; CN
else
	Send, {u+005B} ; EN
}
else
	Send, [
return

+}::
Send, {u+007D}
return

*]::
If (isTypingPinYinWin()=0) ;
{
If (IME_GET()=1) ;1 is CN
	Send, 】 ; CN
else
	Send, {u+005D} ; EN
}
else
	Send, ]
return

+\::
Send, {u+007C}
return

\::
If (IME_GET()=1) ;1 is CN
	Send, 、 ; CN
else
	Send, {u+005C} ; EN
return

+;::
If (IME_GET()=1) ;1 is CN
	Send, ： ; CN
else
	Send, {u+003A} ; EN
return

;::
If (IME_GET()=1) ;1 is CN
	Send, ； ; CN
else
	Send, {u+003B} ; EN
return

'::
If (IME_GET()=1) ;1 is CN
	Send, ‘’{Left} ; CN
else
	Send, {u+0027} ; EN
return

+'::
If (IME_GET()=1) ;1 is CN
	Send, “”{Left} ; CN
else
	Send, {u+0022} ; EN
return

+,::
If (IME_GET()=1) ;1 is CN
	Send, 《 ; CN
else
	Send, {u+003C} ; EN
return

*,::
If (isTypingPinYinWin()=0) ;
{
If (IME_GET()=1) ;1 is CN
	Send, ， ; CN
else
	Send, {u+002C} ; EN
}
else
	Send, ,
return

+.::
If (IME_GET()=1) ;1 is CN
	Send, 》 ; CN
else
	Send, {u+003E} ; EN
return

*.::
If (isTypingPinYinWin()=0) ;
{
If (IME_GET()=1) ;1 is CN
{
	If ((A_PriorHotkey="*1" || A_PriorHotkey="*2" || A_PriorHotkey="*3" || A_PriorHotkey="*4" || A_PriorHotkey="*5" || A_PriorHotkey="*6" || A_PriorHotkey="*7" || A_PriorHotkey="*8" || A_PriorHotkey="*9" || A_PriorHotkey="*0") && TypingSelection=0)
	{
	Send, {u+002E}
	}
	else
	{
	Send, 。 ; CN
	}
}
else
{
	Send, {u+002E} ; EN
}
}
else
{
	Send, .
}
TypingSelection = 1
return

+/::
If (IME_GET()=1) ;1 is CN
	Send, ？ ; CN
else
	Send, {u+003F} ; EN
return

/::
Send, {u+002F} ; EN
return

~Space::
return